package com.example.iot.controller;

import com.example.iot.entity.ArchivesPatchUpgrade;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("/isonline")
@RequiredArgsConstructor
@Component
public class OnLineController {
    LocalDateTime lastTime=LocalDateTime.now();
    DateTimeFormatter formatter  = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    String formattedDateTime = lastTime.format(formatter);
    @GetMapping("/isonline")
    public void isOnLine(String deviceId) {
        LocalDateTime lastTime=LocalDateTime.now();
        DateTimeFormatter formatter  = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String nowTime = lastTime.format(formatter);

        LocalDateTime dateTime1Converted = LocalDateTime.parse(formattedDateTime);
        LocalDateTime dateTime2Converted = LocalDateTime.parse(nowTime);
        Duration duration = Duration.between(dateTime1Converted, dateTime2Converted);
//        if(duration>20)
    }
}
